Fix crash in UTF8ToString with resizable ArrayBuffers#27242
Conversation
sbc100
left a comment
There was a problem hiding this comment.
@guybedford this is the kind of thing you warned me about in our last meeting I think.
The fix does seems reasonable. I do wonder if its worth reverting the GROWABLE_ARRAYBUFFERS defaulting to 1 change (#27212) though (in addition to landing this change).
…rayBuffers getUnsharedTextDecoderView now copies data when the heap buffer is resizable (GROWABLE_ARRAYBUFFERS), and the GROWABLE_ARRAYBUFFERS default is reverted to 0 (as in the upstream 6.0.3 fix), so TextDecoder.decode() no longer rejects the view.
guybedford
left a comment
There was a problem hiding this comment.
This makes sense. In the mean time I'd encourage anyone interested in this space to tackle the spec changes to add resizable support to APIs. There's no technical reason not to support resizable buffers short of doing the spec and implementer reach out with regards to ensuring the right security review.
kleisauke
left a comment
There was a problem hiding this comment.
It looks like you're committing with heyparth@Dhruvs-MacBook-Air.local as your email address. Was that intentional?
(LLVM has a policy on this though I'm not sure whether the same applies to Emscripten)
Split out from emscripten-core#27242. See: emscripten-core#27241
Split out from emscripten-core#27242. See: emscripten-core#27241
Split out from emscripten-core#27242. See: emscripten-core#27241
Split out from emscripten-core#27242. See: emscripten-core#27241
|
@heyparth1 do you have time to look at this today? I'd love to get this fix into a new release ASAP. |
|
Done — the GROWABLE_ARRAYBUFFERS default is reverted to 0 (with a ChangeLog entry; the decode fix stays so the setting still works when enabled explicitly), the settings reference docs are regenerated for build-docs, and I rebaselined the three memory-growth codesize expectations the revert affected. The test-stress failure was just an |
| int main() { | ||
| // Long enough (> 16 bytes) that UTF8ToString on the script string | ||
| // takes the TextDecoder path. | ||
| emscripten_run_script("out('the quick brown fox jumps over the lazy dog')"); |
There was a problem hiding this comment.
Can you just use emscripten_out here rather then emscripten_run_script.
|
Done — switched the test to call |
| This settings does nothing unless ALLOW_MEMORY_GROWTH is set. | ||
|
|
||
| Default value: 1 | ||
| Default value: 0 |
There was a problem hiding this comment.
This change already landed on main in #27260 so I guess you need to rebase or merge?
sbc100
left a comment
There was a problem hiding this comment.
Can you rebase or merge with the main branch and rebase the codesize changes?
|
Do you mind if I push an update to this PR, since it would be good to get it into the next release? |
# Conflicts: # test/codesize/test_codesize_mem_O3_grow.json # test/codesize/test_codesize_mem_O3_grow_standalone.json # test/codesize/test_codesize_minimal_pthreads_memgrowth.json
Hmm.. interesting point yes. I think it would be good to have a valid email address yes, although of course we have not way to verify it. @heyparth1 what email would you like associated with this commit? (Perhaps you should setup your git config with an actual email address?) |
|
Please go ahead and push an update / rebase — I'd love to see this in the next release too. The codesize expectations on the branch are freshly regenerated against the current sources (the three memory-growth files; the other drift the check flagged comes from main and should resolve once main is rebaselined). And apologies for the odd address — please use dhruvsharma52866@gmail.com for the commit; I've fixed my git config so it's used going forward. |
596e589 to
a634c79
Compare
|
Pushed a new version of the branch with email address updated. |
This fixes a crash in
UTF8ToString(and related functions) that occurs when the heap is backed by a resizableArrayBuffer. TheTextDecoder.decode()API throws aTypeErrorwhen passed a view of a resizableArrayBuffer, which previously caused a crash in builds withALLOW_MEMORY_GROWTHandGROWABLE_ARRAYBUFFERSenabled.The
getUnsharedTextDecoderViewfunction insrc/parseTools.mjsis updated to detect when the heap might be resizable and generate code that copies the data using.slice()if the buffer is resizable, ensuringTextDecoderonly receives non-resizable views. A test is added to verify this behavior by emulating the browser's strictTextDecoderimplementation.Closes #27241